package org.truenewx.tnxjee.web.util;

import org.springframework.context.ApplicationContext;

/**
 * Swagger工具类
 */
public class SwaggerUtil {

    private SwaggerUtil() {
    }

    public static boolean isEnabled(ApplicationContext context) {
        ClassLoader classLoader = context.getClassLoader();
        if (classLoader == null) {
            classLoader = Thread.currentThread().getContextClassLoader();
        }
        try {
            Class<?> openApiClass = classLoader.loadClass("io.swagger.v3.oas.models.OpenAPI");
            if (!context.getBeansOfType(openApiClass).isEmpty()) {
                return true;
            }
        } catch (Throwable ignored) {
        }
        return false;
    }

}
